package com.zxjbyte.yiyi.framework.oss.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.util.Arrays;

/**
 * @Author zhangxingjia
 * @Date 2024/7/22 17:59
 * @Version: 1.0
 */
@Getter
public enum OssType {

    ALI_OSS("aliyuncs", "aliyun"), //阿里云

    HUAWEI_OBS("myhuaweicloud", "huaweicloud"), //华为云

    QINIU("qiniucs", "qiniu"), //七牛云

    TENCENT("myqcloud", "tencent"), //腾讯云

    JDCLOUD("jdcloud", "jdcloud"), //京东云

    KSYUN_CS("ksyuncs", "ksyun"), // 金山云

    BCE_BOS("bcebos", "baidu"), // 百度云
    ;

    // 访问域名关键字
    private final String keyword;

    // 三方存储服务
    private final String storageService;

    OssType(String keyword, String storageService) {
        this.keyword = keyword;
        this.storageService = storageService;
    }

    public static OssType getOssType(String endpoint){
        return Arrays.stream(values()).filter(f -> StrUtil.contains(endpoint, f.getKeyword())).findFirst().orElse(null);
    }

    public static String getStorageService(String endpoint){
        OssType ossType = getOssType(endpoint);
        if(ossType == null){
            return "minio";
        }
        return ossType.getStorageService();
    }
}
